const {ccclass, property} = cc._decorator;
declare let eManager, dbh, DBManager, i18n, JsonHttp;
import BaseView from '../../component/BaseView';
import GaoGuang from "./../GaoGuang";
import CaBiZi from "./../CaBiZi";
import KouHong from "./../KouHong";
import UIHelper = require("../../component/UIHelper");

//美妆（已有眼妆）
@ccclass
export default class HuaZhuangFourView extends BaseView {
    //触摸区域
    @property(cc.Node)
    bg: cc.Node = null;
    //阴影
    @property(GaoGuang)
    YinYing: GaoGuang = null;
    //鼻影 高光
    @property(CaBiZi)
    CaBiZi: CaBiZi = null;
    //腮红
    @property(GaoGuang)
    SaiHong: GaoGuang = null;
    //口红
    @property(KouHong)
    KouHong: KouHong = null;


    //下一步
    @property(cc.Node)
    nodeNextPoint: cc.Node = null;
    //完成
    @property(cc.Node)
    nodeDone: cc.Node = null;

    @property(cc.Node)
    btnClose: cc.Node = null;

    _point = 1;
    _isPlay = false;
    _isStart = false;//是否是剧情前触发
    onLoad() {
        super.onLoad();
        this.bg.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.bg.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        eManager.on("HZ_REFRESH_ICON_TIPS", this.showIconTips, this)
        eManager.on("MINI_DONE_POINT", this.donePoint, this)
        eManager.on("MINI_DONE_STEP", this.doneStep, this)
        //@ts-ignore
        this._isStart = this.node.openParam;
    };

    onClose() {
    };

    start() {
        super.start();
        this.btnClose.active = !this._isStart;
        this.updatePointShow();
    };

    donePoint(point: number) {
        this.nodeNextPoint.active = true;
    };

    doneStep() {
        this.nodeDone.active = true;
    };

    updatePointShow() {
        this.YinYing.node.active = this._point == 1;
        this.CaBiZi.node.active = this._point == 2;
        this.SaiHong.node.active = this._point == 3;
        this.KouHong.node.active = this._point == 4;
        switch (this._point) {
            case 1:
                this.YinYing.initData();
                break;
            case 2:
                this.CaBiZi.initData();
                break;
            case 3:
                this.SaiHong.initData();
                break;
            case 4:
                this.KouHong.initData();
                break;
        }
        // Initializer.huaZhuangProxy.sendMakeDot(6,this._point,1);
    };

    //展示提示图片
    showIconTips(name) {

    };

    //下一小阶段
    onClickNextPoint() {
        this.nodeNextPoint.active = false;
        this._point++;
        this.updatePointShow();
    };

    onTouchStart(event) {
        switch (this._point) {
            case 1:
                this.YinYing._touchStart(event, "yinying");
                break;
            case 2:
                this.CaBiZi._touchStart(event);
                break;
            case 3:
                this.SaiHong._touchStart(event, "saihong");
                break;
            case 4:
                this.KouHong._touchStart(event);
                break;
        }
    };

    onTouchMove(event) {
        switch (this._point) {
            case 1:
                this.YinYing._touchMove(event);
                break;
            case 2:
                this.CaBiZi._touchMove(event);
                break;
            case 3:
                this.SaiHong._touchMove(event);
                break;
            case 4:
                this.KouHong._touchMove(event);
                break;
        }
    };

    onTouchEnd(event) {
        switch (this._point) {
            case 1:
                this.YinYing._touchEnd(event, "yinying");
                break;
            case 2:
                this.CaBiZi._touchEnd(event);
                break;
            case 3:
                this.SaiHong._touchEnd(event, "saihong");
                break;
            case 4:
                this.KouHong._touchEnd(event);
                break;
        }
    };

    onClickEnd(isSkip) {
        let next = this.params.next && this.params.next.shift();
        if (next) {
            UIHelper.openUI(next, {
                next: this.params.next
            })
            this.node.destroy();
        }
    };

    onClickSkip() {
        this.onClickEnd(true);
    };

}
